package coml.jiyun.hp.wanandroid;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import java.util.ArrayList;

import coml.jiyun.hp.wanandroid.ui.adapter.HomeAdapter;
import coml.jiyun.hp.wanandroid.ui.adapter.MainAdapter;
import coml.jiyun.hp.wanandroid.ui.fragment.HomeFragment;
import coml.jiyun.hp.wanandroid.ui.fragment.SquareFragment;

public class MainActivity extends AppCompatActivity {

    /**
     * 首页
     */
    private ViewPager mMainVp;
    private ArrayList<Fragment> fragments;
    private ArrayList<Fragment> allfragments;
    private HomeAdapter homeAdapter;
    private TabLayout mMainTab;
    /**
     * 首页
     */
    private TextView mMainToolTv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        mMainVp = (ViewPager) findViewById(R.id.main_vp);
//        mMainTab = (TabLayout) findViewById(R.id.main_tab);
//        mMainToolTv = (TextView) findViewById(R.id.main_tool_tv);

        fragments = new ArrayList<>();
        fragments.add(new SquareFragment());
        fragments.add(new HomeFragment());

        MainAdapter mainAdapter = new MainAdapter(getSupportFragmentManager(), fragments);
        mMainVp.setAdapter(mainAdapter);
        mMainVp.setCurrentItem(1);
//        mMainTab.setupWithViewPager(mMainVp);
//
//        allfragments = new ArrayList<>();
//        allfragments.add(new HomeFragment());
//        allfragments.add(new AnswerFragment());
//        allfragments.add(new SystemFragment());
//        allfragments.add(new MyFragment());
//
//        homeAdapter = new HomeAdapter(getSupportFragmentManager(), allfragments);
//        mMainVp.setAdapter(homeAdapter);
//        mMainTab.setupWithViewPager(mMainVp);
//
//        mMainTab.getTabAt(0).setText("首页").setIcon(R.drawable.home);
//        mMainTab.getTabAt(1).setText("问答").setIcon(R.drawable.answer);
//        mMainTab.getTabAt(2).setText("体系").setIcon(R.drawable.system);
//        mMainTab.getTabAt(3).setText("我的").setIcon(R.drawable.my);
//        mMainTab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
//            @Override
//            public void onTabSelected(TabLayout.Tab tab) {
//                int position = tab.getPosition();
//                if (position == 0) {
//                    mMainToolTv.setText("首页");
//                }
//                if (position == 1) {
//                    mMainToolTv.setText("问答");
//                }
//                if (position == 2) {
//                    mMainToolTv.setText("体系");
//                }
//                if (position == 3) {
//                    mMainToolTv.setText("我的");
//                }
//            }
//
//            @Override
//            public void onTabUnselected(TabLayout.Tab tab) {
//
//            }
//
//            @Override
//            public void onTabReselected(TabLayout.Tab tab) {
//
//            }
//        });





    }


}